package javathinking.chapter5;

public class Book {
    boolean checkedOut;

    public Book(boolean checkedOut) {
        this.checkedOut = checkedOut;
    }

    void checkIn() {
        checkedOut = false;
    }

    /**
     * 所有的Book对象再被当做垃圾回收前都应该被签入
     */
    @Override
    protected void finalize() throws Throwable {
        if (checkedOut) {
            System.out.println("Error: checked out");
            //super.finalize();
        }
    }

}

class TerminationCondition {
    public static void main(String[] args) {
        Book novel = new Book(true);
        novel.checkIn();
        new Book(true);
        System.gc();
    }
}